package yyy.ab.modules.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import yyy.ab.common.core.BaseController;
import yyy.ab.common.core.ResultBean;
import yyy.ab.modules.system.entity.SysAppModule;
import yyy.ab.modules.system.service.SysAppModuleService;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

@RestController
@RequiredArgsConstructor
@Api(tags = "系统：应用模块管理")
@RequestMapping("/system/appModule")
public class SysAppModuleController extends BaseController {

    private final SysAppModuleService service;

    /**
     * 应用模块页面
     */
    @RequestMapping
    @PreAuthorize("@ab.check('appModule:list')")
    public ModelAndView jump() {
        ModelAndView view = new ModelAndView();
        view.setViewName("system/appModule/index");
        return view;
    }

    //    @Log("查询应用模块")
    @ApiOperation("查询应用模块")
    @GetMapping("/findPage")
    public Object query(@RequestParam Map<String, Object> params) {
        IPage<SysAppModule> page = service.findPage(params);
        return jsonForTable(page);
    }

    @ApiOperation("查询单个应用模块")
    @GetMapping("/get")
    public SysAppModule get(Long id) {
        SysAppModule appModule = service.getById(id);
        return appModule;
    }

    @ApiOperation("创建应用模块")
    @PostMapping
    public Object create(@RequestBody SysAppModule appModule) {
        ResultBean resultBean = service.create(appModule);
        return resultBean;
    }

    @ApiOperation("修改应用模块")
    @PutMapping
    public Object update(@RequestBody SysAppModule appModule) {
        ResultBean resultBean = service.update(appModule);
        return resultBean;
    }

    public Object delete(@RequestBody Long id) {
        ResultBean resultBean = service.delete(id);
        return resultBean;
    }

    @ApiOperation("删除应用模块")
    @DeleteMapping
    public Object deleteAll(@RequestBody Long[] ids) {
        List<Long> idList = Arrays.asList(ids);
        ResultBean resultBean = service.deleteAll(idList);
        return resultBean;
    }
}
